package com.hu.hutool.ThreadUtil;

import cn.hutool.core.util.RandomUtil;
import com.commons.tools.utils.SpringContextUtil;
import com.hu.hutool.dao.UserDao;
import com.hu.hutool.entity.User;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;

/**
 * @Author CazCen
 * @Date 2021/11/16 21:32
 */
@Slf4j
public class CallableB2 implements Callable {

    /**
     * 多线程不能使用bean注入的方式获取bean
     */
    private UserDao userDao = (UserDao) SpringContextUtil.getBean("userDao");

    @Override
    public Object call() throws Exception {
        log.info("ThreadName：{}", Thread.currentThread().getName());
        User user = new User();
        user.setName("AA");
        user.setPhone("15302746526");
        user.setAge(RandomUtil.randomInt(10, 30));
        userDao.insert(user);
        log.info("id:{}", user.getId());
        return null;
    }
}
